package com.coc.client;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName;

public class CxfClient {
	public static void main(String[] args) {
		CxfClient.main3();
	}

	public static void main3() {
		Object retObj = null;

		Call call = null;

		Service service = new Service();

		// 去掉缓存，以支持并发
		try {
			call = (Call) service.createCall();
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage(), e);
		}
		// 设置远程地址
		call.setTargetEndpointAddress("http://127.0.0.1:8080/WebService/services/MessageService");
		// 清空操作
		call.clearOperation();
		// 清空头
		call.clearHeaders();

		// Object[] body = new Object[]{"1","getMessageMarks"};
		// Object[] body = new Object[]{"1"};
		Object[] body = new Object[2];
		body[0] = "sssssssssssssssssssss";
		body[1] = "12314ed56";
		// retObj = invokeMethod(call, "getMessageInfo", body);
		retObj = invokeMethod(call, "getMessageMarks", body);
//		retObj = invokeMethod(call, "getMessageMarks", "awm","123");
		System.out.println(retObj.toString());

	}

	private static Object invokeMethod(Call call, String opName, Object... paras) {
		Object retObj = null;
		// 设置要调用的方法
		call.setOperationName(opName);

		// 已server-config.wsdd方式方式发布  不需要设置以下参数
//		call.setOperationName(new QName("http://com.coc.ws", opName));
//		call.addParameter("messageNo", XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
//		call.addParameter("subjectNo", XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
//		call.setReturnType(XMLType.XSD_STRING);
//		call.setUseSOAPAction(true);

		// 该方法需要的参数
		Object[] objs = new Object[paras.length];
		int a = 0;
		for (Object objpara : paras) {
			objs[a] = objpara;
			a++;
		}
		try {
			// 调用该方法
			retObj = call.invoke(objs);
		} catch (Exception e) {
			throw new RuntimeException("原因：" + e.getMessage(), e);
		}
		return retObj;
	}
}
